package com.mariusz.ui.models;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.mariusz.data.dto.Payment;

public class PaymentsTableModel extends AbstractTableModel {
	private static final String[] PAYMENTS_TABLE_HEADER = new String[] {
			"Id","Payment Date", "Payment Amount", "Is Paied", "Notes..." };
	private List<Payment> payments;

	public PaymentsTableModel(List<Payment> payments) {
		super();
		this.payments = payments;
	}

	@Override
	public int getColumnCount() {
		return PAYMENTS_TABLE_HEADER.length;
	}

	public String getColumnName(int i) {
		return PAYMENTS_TABLE_HEADER[i];
	}

	@Override
	public int getRowCount() {
		if (payments != null) {
			return payments.size();
		} else {
			return 0;
		}
	}

	public Class getColumnClass(int c) {
		return getValueAt(0, c).getClass();
	}

	public boolean isCellEditable(int row, int col) {
		if (col >= 3) {
			return true;
		} else {
			return false;
		}
	}

	public void setValueAt(Object value, int row, int col) {
		switch (col) {
		case 0:
		case 1: 
		case 2: break;
		
		case 3:
			payments.get(row).setPaied((Boolean)value);
			 	break;
		case 4:
			payments.get(row).setNotes((String)value);
				break;
		}
	}

	@Override
	public Object getValueAt(int row, int col) {
		switch (col) {
		case 0: 
			return row;
		case 1:
			return payments.get(row).getPaymentDate();
		case 2:
			return payments.get(row).getAmount();
		case 3:
			return payments.get(row).isPaied();
		case 4:
			return payments.get(row).getNotes();
		}
		return null;
	}
}
